Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Jun 9, 2025

Description

Fixes #4201

Adds AWS Bedrock Extended Thinking support for Claude Sonnet 4, Opus 4, and 3.7 Sonnet models. Users can now enable reasoning mode when using AWS Bedrock, matching the functionality available with the direct Anthropic provider.

Changes Made

API Implementation:

  • Added additionalModelRequestFields.thinking configuration to Bedrock API payloads
  • Enhanced stream processing to handle reasoning content blocks (contentBlockStart, contentBlockDelta)
  • Added required anthropic_version parameter for thinking requests
  • Integrated with existing shouldUseReasoningBudget() logic

UI Updates:

  • ThinkingBudget component now properly handles Bedrock models
  • Fixed conditional rendering in ApiOptions to show controls when models are loaded
  • Improved max tokens slider calculation for reasoning-enabled models

Testing:

  • Added comprehensive unit tests for reasoning functionality
  • Verified stream processing and error handling

Technical Details

  • Uses existing reasoning budget UI rather than separate :thinking model variants
  • Automatically excludes topP parameter when thinking is enabled (AWS requirement)
  • Handles multiple AWS SDK reasoning content structures
  • Maintains backward compatibility

Testing

  • All existing tests pass
  • New unit tests cover reasoning configuration and stream processing
  • Manual testing confirmed reasoning works with Claude Sonnet 4 on Bedrock

Files Changed

  • packages/types/src/providers/bedrock.ts - Type definitions for reasoning
  • src/api/providers/bedrock.ts - Core thinking functionality
  • src/api/providers/__tests__/bedrock-reasoning.test.ts - Test coverage
  • webview-ui/src/components/settings/ - UI improvements for reasoning controls

Important

Adds AWS Bedrock Extended Thinking support for Claude models, enabling reasoning mode with API, UI, and testing updates.

  • Behavior:
    • Adds additionalModelRequestFields.thinking to Bedrock API payloads in bedrock.ts.
    • Handles reasoning content blocks (contentBlockStart, contentBlockDelta) in bedrock.ts.
    • Introduces anthropic_version parameter for thinking requests in bedrock.ts.
    • Integrates with shouldUseReasoningBudget() logic in bedrock.ts.
  • UI Updates:
    • Updates ThinkingBudget component to handle Bedrock models.
    • Fixes conditional rendering in ApiOptions for model controls.
    • Improves max tokens slider for reasoning-enabled models.
  • Testing:
    • Adds unit tests for reasoning functionality in bedrock-reasoning.spec.ts.
    • Verifies stream processing and error handling in bedrock-reasoning.spec.ts.

This description was created by Ellipsis for 13e272c. You can customize this summary. It will automatically update as commits are pushed.

hannesrudolph and others added 7 commits June 7, 2025 12:23
- Refactor Bedrock provider for clarity and type safety.
- Extract constants and helper methods.
- Update documentation.
- Rename and update reasoning tests to Vitest.
- Ensure all tests pass.
- Add StreamChunk interface with proper type definitions
- Update all generator methods to use Generator<StreamChunk, void, unknown>
- Addresses review feedback for better type safety
- Replace custom StreamChunk interface with ApiStreamChunk import
- Update all generator method signatures to use ApiStreamChunk
- Fixes type compatibility issues with yield* delegation
- Resolves CI test failures related to type mismatches
…bility

- Replace multiple handler methods with unified processStreamEvent()
- Simplify main stream processing loop from ~30 lines to 1 line
- Maintain all existing functionality and test coverage
- Address PR reviewer feedback for improved code organization

Addresses: Stream processing consolidation suggestion from PR review
@hannesrudolph hannesrudolph requested review from cte, jr and mrubens as code owners June 9, 2025 22:28
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jun 9, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 9, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jun 9, 2025
/**
* Determines if extended thinking should be enabled based on model support and user settings
*/
private shouldEnableExtendedThinking(modelInfo: ModelInfo, params: any): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider replacing the use of any for the parameter params in shouldEnableExtendedThinking() with a more specific type. This will improve type safety and clarity.

Suggested change
private shouldEnableExtendedThinking(modelInfo: ModelInfo, params: any): boolean {
private shouldEnableExtendedThinking(modelInfo: ModelInfo, params: { reasoning?: boolean; reasoningBudget?: number }): boolean {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

AWS Bedrock does not show or support Sonnet and Opus 4 Extended Thinking

3 participants